package com.shallowUniverse.dmp.netty.channel;

import com.shallowUniverse.dmp.netty.handler.HttpChannelHandler;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpObjectAggregator;
import io.netty.handler.codec.http.HttpRequestDecoder;
import io.netty.handler.codec.http.HttpResponseEncoder;

/**
 * @author Shuai Guo
 * @version 1.0
 * @description
 * @date 2021/8/5
 */
public class NettyChannelInitializer extends ChannelInitializer<SocketChannel> {

    @Override
    protected void initChannel(SocketChannel socketChannel) throws Exception {
        socketChannel.pipeline()
                .addLast("decoder", new HttpRequestDecoder())   // 1
                .addLast("encoder", new HttpResponseEncoder())  // 2
                .addLast("aggregator", new HttpObjectAggregator(512 * 1024))    // 3
                .addLast("handler", new HttpChannelHandler());        // 4
    }
}
